//
//  BaseNavigationController.m
//  HengYouCai
//
//  Created by ycgwl on 2017/4/26.
//  Copyright © 2017年 lwj. All rights reserved.
//

#import "BaseNavigationController.h"
#import "BannerWebViewVC.h"
#import "AppDelegate.h"


@interface BaseNavigationController ()<UIGestureRecognizerDelegate,UINavigationBarDelegate>

@end

@implementation BaseNavigationController


- (void)viewDidLoad {
    [super viewDidLoad];
//    self.interactivePopGestureRecognizer.delegate = self;
    //    // 方式1：使用自己的图片替换原来的返回图片
    self.navigationBar.backIndicatorImage = [UIImage imageNamed:@"back"];
    self.navigationBar.backIndicatorTransitionMaskImage = [UIImage imageNamed:@"back"];
//    [UINavigationBar appearance].tintAdjustmentMode = UIViewTintAdjustmentModeAutomatic;
    //     导航栏标题样式
//    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:Normal_333Color}];
}


#pragma mark - <UIGestureRecognizerDelegate>
/**
 *  手势识别器对象会调用这个代理方法来决定手势是否有效
 *
 *  @return YES : 手势有效, NO : 手势无效
 */
//- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
//{
//    //    if (self.childViewControllers.count == 1) { // 导航控制器中只有1个子控制器
//    //        return NO;
//    //    }
//    //    return YES;
//
//    //从广告页进入的BannerViewVC手势禁止
//    if ([self.topViewController isMemberOfClass:[BannerWebViewVC class]]) {
//        BannerWebViewVC * vc = (BannerWebViewVC *)self.topViewController;
//        if (vc.isFromADGuide) {//从广告页进入的
//            return NO;
//        }
//    }
//    // 手势何时有效 : 当导航控制器的子控制器个数 > 1就有效
//    return self.childViewControllers.count > 1;
//}


/**
 *  重写push方法的目的 : 拦截所有push进来的子控制器
 *
 *  @param viewController 刚刚push进来的子控制器
 */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    //消除系统自带的返回标题
    viewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    if (self.childViewControllers.count > 0) { // 如果viewController不是最早push进来的子控制器
        // 左上角
        //        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //        [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        //        [backButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateHighlighted];
        //        //iOS11之后系统返回触碰范围优化取消了 加上这个自己优化
        //        [backButton setTitle:@"            " forState:UIControlStateNormal];
        //        [backButton sizeToFit];
        //        // 这句代码放在sizeToFit后面
        //        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
        //        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        //        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        
        
        // 隐藏底部的工具条
        viewController.hidesBottomBarWhenPushed = YES;
    }
    // 所有设置搞定后, 再push控制器
    [super pushViewController:viewController animated:animated];
}
//
//- (UIViewController *)popViewControllerAnimated:(BOOL)animated{
//    UIViewController * popViewController = [super popViewControllerAnimated:animated];
//    NSDictionary * dic1 = self.visibleViewController.navigationController.navigationBar.titleTextAttributes;
//    //返回前
//    if (dic1) {
//        self.navigationBar.titleTextAttributes = dic1;
//    }
//
//    @weakify(self)
//    [self.transitionCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext>  _Nonnull context) {
////        @strongify(self)
//        NSDictionary * dic2 = self_weak_.visibleViewController.navigationController.navigationBar.titleTextAttributes;
//        if (dic2) {
//            self_weak_.navigationBar.titleTextAttributes = dic1;
//        }
//
//    }];
//
//    return popViewController;
//}


@end
